﻿CREATE TABLE [dbo].[Mobile_Settings] (
    [CompanyName]  NVARCHAR (50)   NULL,
    [Address]      NVARCHAR (200)  NULL,
    [CompanyPhone] NVARCHAR (20)   NULL,
    [MobilePhone]  NVARCHAR (20)   NULL,
    [Email]        NVARCHAR (30)   NULL,
    [Website]      NVARCHAR (50)   NULL,
    [Fblink]       NVARCHAR (50)   NULL,
    [Longitude]    DECIMAL (18, 9) NULL,
    [Latitude]     DECIMAL (18, 9) NULL,
    [Disclaimer]   NVARCHAR (MAX)  NULL,
    [AboutUs]      NVARCHAR (MAX)  NULL,
    [Module0]      NVARCHAR (50)   NULL,
    [Module1]      NVARCHAR (50)   NULL,
    [Module2]      NVARCHAR (50)   NULL,
    [Module3]      NVARCHAR (50)   NULL,
    [Module4]      NVARCHAR (50)   NULL,
    [Module5]      NVARCHAR (50)   NULL,
    [Module6]      NVARCHAR (50)   NULL,
    [Module7]      NVARCHAR (50)   NULL,
    [Module8]      NVARCHAR (50)   NULL,
    [Module9]      NVARCHAR (50)   NULL,
    [Module10]     NVARCHAR (50)   NULL,
    [Module11]     NVARCHAR (50)   NULL,
    [Module12]     NVARCHAR (50)   NULL,
    [Module13]     NVARCHAR (50)   NULL,
    [CreateDate]   DATETIME        CONSTRAINT [DF_Mobile_Settings_CreateDate] DEFAULT (getdate()) NOT NULL,
    [StatusDelete] TINYINT         CONSTRAINT [DF_Mobile_Settings_StatusDelete] DEFAULT ((0)) NOT NULL,
    [PrimaryKey]   INT             NOT NULL,
    [Module14]     NVARCHAR (50)   NULL,
    [Module15]     NVARCHAR (50)   NULL,
    [Module16]     NVARCHAR (50)   NULL,
    [Module17]     NVARCHAR (50)   NULL,
    [Module18]     NVARCHAR (50)   NULL,
    [Module19]     NVARCHAR (50)   NULL,
    [Module20]     NVARCHAR (50)   NULL,
    [Module21]     NVARCHAR (50)   NULL,
    [Module22]     NVARCHAR (MAX)  NULL,
    CONSTRAINT [PrimaryKey_d666da05-24aa-4282-8681-4347e460f4b8] PRIMARY KEY NONCLUSTERED ([PrimaryKey] ASC)
);




GO
CREATE CLUSTERED INDEX [ci_azure_fixup_dbo_Mobile_Settings]
    ON [dbo].[Mobile_Settings]([CompanyName] ASC);


GO
CREATE TRIGGER [dbo].[Mobile_Settings_dss_update_trigger] ON [dbo].[Mobile_Settings] FOR UPDATE AS
SET NOCOUNT ON
DECLARE @marker_create_scope_local_id INT
DECLARE @marker_scope_create_peer_timestamp BIGINT
DECLARE @marker_scope_create_peer_key INT
DECLARE @marker_local_create_peer_timestamp BIGINT
DECLARE @marker_local_create_peer_key INT
DECLARE @marker_state INT
SELECT TOP 1 @marker_create_scope_local_id = [provision_scope_local_id], @marker_local_create_peer_timestamp = [provision_timestamp], @marker_local_create_peer_key = [provision_local_peer_key], @marker_scope_create_peer_timestamp = [provision_scope_peer_timestamp], @marker_scope_create_peer_key = [provision_scope_peer_key], @marker_state = [state]
FROM [DataSync].[provision_marker_dss]
WHERE [object_id] = 1959886249 
 AND [owner_scope_local_id] = 0

MERGE [DataSync].[Mobile_Settings_dss_tracking] AS [target] 
USING (SELECT [i].[PrimaryKey] FROM INSERTED AS [i]) AS source([PrimaryKey]) 
ON ([target].[PrimaryKey] = [source].[PrimaryKey])
WHEN MATCHED THEN
UPDATE SET [sync_row_is_tombstone] = 0, 
[local_update_peer_key] = 0, 
[update_scope_local_id] = NULL, [last_change_datetime] = GETDATE()
WHEN NOT MATCHED THEN
INSERT (
[PrimaryKey] ,
[create_scope_local_id], [scope_create_peer_key], [scope_create_peer_timestamp], [local_create_peer_key], [local_create_peer_timestamp], [update_scope_local_id], [local_update_peer_key], [sync_row_is_tombstone], [last_change_datetime]) 
VALUES (
[source].[PrimaryKey],@marker_create_scope_local_id, @marker_scope_create_peer_key, @marker_scope_create_peer_timestamp, 0, @marker_local_create_peer_timestamp , NULL, 0, 0, GETDATE() );
GO
CREATE TRIGGER [dbo].[Mobile_Settings_dss_insert_trigger] ON [dbo].[Mobile_Settings] FOR INSERT AS
SET NOCOUNT ON
DECLARE @marker_create_scope_local_id INT
DECLARE @marker_scope_create_peer_timestamp BIGINT
DECLARE @marker_scope_create_peer_key INT
DECLARE @marker_local_create_peer_timestamp BIGINT
DECLARE @marker_local_create_peer_key INT
DECLARE @marker_state INT
SELECT TOP 1 @marker_create_scope_local_id = [provision_scope_local_id], @marker_local_create_peer_timestamp = [provision_timestamp], @marker_local_create_peer_key = [provision_local_peer_key], @marker_scope_create_peer_timestamp = [provision_scope_peer_timestamp], @marker_scope_create_peer_key = [provision_scope_peer_key], @marker_state = [state]
FROM [DataSync].[provision_marker_dss]
WHERE [object_id] = 1959886249 
 AND [owner_scope_local_id] = 0

MERGE [DataSync].[Mobile_Settings_dss_tracking] AS [target] 
USING (SELECT [i].[PrimaryKey] FROM INSERTED AS [i]) AS source([PrimaryKey]) 
ON ([target].[PrimaryKey] = [source].[PrimaryKey])
WHEN MATCHED THEN
UPDATE SET [sync_row_is_tombstone] = 0, 
[local_update_peer_key] = 0, 
[update_scope_local_id] = NULL, [last_change_datetime] = GETDATE()
WHEN NOT MATCHED THEN
INSERT (
[PrimaryKey] ,
[create_scope_local_id], [scope_create_peer_key], [scope_create_peer_timestamp], [local_create_peer_key], [local_create_peer_timestamp], [update_scope_local_id], [local_update_peer_key], [sync_row_is_tombstone], [last_change_datetime]) 
VALUES (
[source].[PrimaryKey],NULL, NULL, NULL, 0, CAST(@@DBTS AS BIGINT) + 1, NULL, 0, 0, GETDATE() );
GO
CREATE TRIGGER [dbo].[Mobile_Settings_dss_delete_trigger] ON [dbo].[Mobile_Settings] FOR DELETE AS
SET NOCOUNT ON
DECLARE @marker_create_scope_local_id INT
DECLARE @marker_scope_create_peer_timestamp BIGINT
DECLARE @marker_scope_create_peer_key INT
DECLARE @marker_local_create_peer_timestamp BIGINT
DECLARE @marker_local_create_peer_key INT
DECLARE @marker_state INT
SELECT TOP 1 @marker_create_scope_local_id = [provision_scope_local_id], @marker_local_create_peer_timestamp = [provision_timestamp], @marker_local_create_peer_key = [provision_local_peer_key], @marker_scope_create_peer_timestamp = [provision_scope_peer_timestamp], @marker_scope_create_peer_key = [provision_scope_peer_key], @marker_state = [state]
FROM [DataSync].[provision_marker_dss]
WHERE [object_id] = 1959886249 
 AND [owner_scope_local_id] = 0

MERGE [DataSync].[Mobile_Settings_dss_tracking] AS [target] 
USING (SELECT [i].[PrimaryKey] FROM DELETED AS [i]) AS source([PrimaryKey]) 
ON ([target].[PrimaryKey] = [source].[PrimaryKey])
WHEN MATCHED THEN
UPDATE SET [sync_row_is_tombstone] = 1, 
[local_update_peer_key] = 0, 
[update_scope_local_id] = NULL, [last_change_datetime] = GETDATE()
WHEN NOT MATCHED THEN
INSERT (
[PrimaryKey] ,
[create_scope_local_id], [scope_create_peer_key], [scope_create_peer_timestamp], [local_create_peer_key], [local_create_peer_timestamp], [update_scope_local_id], [local_update_peer_key], [sync_row_is_tombstone], [last_change_datetime]) 
VALUES (
[source].[PrimaryKey],@marker_create_scope_local_id, @marker_scope_create_peer_key, @marker_scope_create_peer_timestamp, 0, @marker_local_create_peer_timestamp , NULL, 0, 1, GETDATE() );